package com.yanqu.road.dao.impl.activity.seacraft;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.seacraft.pirateriot.config.SeacraftPirateRiotEquipConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SeacraftPirateRiotEquipConfigDaoImpl extends TempDao {

    private static String getSeacraftPirateRiotEquipConfigSql = "select * from `t_s_activity_seacraft_equip` where `activityId`=?";

    public Map<Integer, SeacraftPirateRiotEquipConfig> getSeacraftPirateRiotEquipConfigMap(int activityId) {
        Map<Integer, SeacraftPirateRiotEquipConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSeacraftPirateRiotEquipConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SeacraftPirateRiotEquipConfig seacraftPirateRiotEquipConfig = new SeacraftPirateRiotEquipConfig();
                seacraftPirateRiotEquipConfig.setActivityId(rs.getInt("activityId"));
                seacraftPirateRiotEquipConfig.setLevel(rs.getInt("level"));
                seacraftPirateRiotEquipConfig.setAttack(rs.getLong("attack"));
                seacraftPirateRiotEquipConfig.setHp(rs.getLong("hp"));
                seacraftPirateRiotEquipConfig.setConsume(rs.getString("consume"));
                map.put(seacraftPirateRiotEquipConfig.getLevel(), seacraftPirateRiotEquipConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
